import java.util.concurrent.locks.Lock;

public class Test {
    public static final int THREAD_COUNT = 3;
    public static volatile  int start = 0;
    public static final int end = 100;
     public static final  Object lock = new Object();

      public   static class  Num implements Runnable{
          public int index;

          public Num(int index){
             this.index = index;
          }

          @Override
          public void run() {
              while (end > start){
                  synchronized (lock){
                      //判断当前不是应该来的线程则让线程等待
                      while (start%THREAD_COUNT != index && start<= end){
                          try {
                              lock.wait();
                          } catch (InterruptedException e) {
                              e.printStackTrace();
                          }

                      }
                      if (end >= start){


                          System.out.println("当前线程为Thread" + (index+1)+"开始进行操作,操作数为-------------------------------" + start );
                          start++;

                          lock.notifyAll();

                      }


                  }
              }
          }
      }

    public static void main(String[] args) {
        for (int i = 0; i < THREAD_COUNT; i++) {
            new Thread(new Num(i)).start();

        }
    }
}
